Skip to main content

ssh

Introduction

This cheat sheet provides a quick reference for some common ssh (Secure Shell) commands and concepts. ssh is a secure protocol used for remote login and secure file transfer.

ssh Concepts

Basic ssh Usage

ssh is used for secure remote access to servers and network devices.

  • Connect to a remote server:

    ssh username@remote-host
  • Connect to a remote server on a specific port:

    ssh -p port username@remote-host
  • Securely copy files to a remote server:

    scp local-file username@remote-host:/path/to/remote-directory
  • Securely copy files from a remote server to the local machine:

    scp username@remote-host:/path/to/remote-file local-directory

SSH Keys

SSH keys provide passwordless authentication.

  • Generate an SSH key pair:

    ssh-keygen -t rsa -b 4096
  • Copy your SSH public key to a remote server:

    ssh-copy-id username@remote-host

Port Forwarding

SSH can be used for port forwarding, allowing secure access to services on a remote server.

  • Local port forwarding (forward local port to a remote server):

    ssh -L local-port:remote-host:remote-port username@remote-host
  • Remote port forwarding (forward remote port to a local machine):

    ssh -R remote-port:local-host:local-port username@remote-host

SSH Config

Use SSH config files for custom settings.

  • Edit or create SSH config file:

    nano ~/.ssh/config
  • Use SSH config file for connections:

    ssh custom-alias

ssh Command-Line

  • Connect to a remote server:

    ssh username@remote-host
  • Connect to a remote server on a specific port:

    ssh -p port username@remote-host
  • Securely copy files to a remote server:

    scp local-file username@remote-host:/path/to/remote-directory
  • Securely copy files from a remote server to the local machine:

    scp username@remote-host:/path/to/remote-file local-directory
  • Generate an SSH key pair:

    ssh-keygen -t rsa -b 4096
  • Copy your SSH public key to a remote server:

    ssh-copy-id username@remote-host
  • Local port forwarding (forward local port to a remote server):

    ssh -L local-port:remote-host:remote-port username@remote-host
  • Remote port forwarding (forward remote port to a local machine):

    ssh -R remote-port:local-host:local-port username@remote-host
  • Edit or create SSH config file:

    nano ~/.ssh/config
  • Use SSH config file for connections:

    ssh custom-alias

Conclusion

This cheat sheet covers some common ssh (Secure Shell) commands and concepts. ssh is a versatile tool for secure remote access and file transfer, making it essential for system administrators and network operations; refer to the OpenSSH documentation for more in-depth information and advanced usage.